package LeetCode;

import Constructs.ListNode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/6/15.
//
//https://leetcode.cn/problems/remove-linked-list-elements/description/
public class 移除链表元素 {
    public static void main(String[] args) {

    }
    public static ListNode removeElements(ListNode head, int val) {
        ListNode newHead = new ListNode(0,head);
        if(newHead.next == null)return newHead.next;
        ListNode pre = newHead,next = newHead.next;
        while (next != null){
            if(next.value == val){
                pre.next = next.next;
                next = pre.next;
            }else {
                pre = next;
                next = next.next;
            }
        }
        return newHead.next;
    }
}
